/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufg.inf.si.poo.formula1.GUI;

import br.ufg.inf.si.poo.formula1.Interface.InterfaceRegister;
import br.ufg.inf.si.poo.formula1.Library.Library;
import br.ufg.inf.si.poo.formula1.ManagementFiles.ManagementFiles;
import br.ufg.inf.si.poo.formula1.Team.Team;
import java.text.ParseException;
import javax.swing.JOptionPane;

/**
 * RegisterTeam
 *
 * Versao 1.0
 *
 * Data 16/02/2013
 *
 * @author Igor
 */
public class RegisterTeam extends javax.swing.JInternalFrame implements InterfaceRegister {
    //Atributos
    private Team team;
    private Boolean emEdicao; //Valida se esta em modo de edicao ou nao
    private Boolean novo; //Variavel que verifica se clicou no botao de novo registro

    //Construtores
    /**
     * Creates new form RegisterTeam
     */
    public RegisterTeam() {
        initComponents();
        this.novo = false;
        clearFields();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelTitulo = new javax.swing.JPanel();
        labelTitulo = new javax.swing.JLabel();
        panelDadosPrincipais = new javax.swing.JPanel();
        panelEquipesCadastradas = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        listEquipes = new javax.swing.JList();
        labelNomeCompleto = new javax.swing.JLabel();
        textNomeCompleto = new javax.swing.JTextField();
        labelNome = new javax.swing.JLabel();
        textNome = new javax.swing.JTextField();
        labelDiretor = new javax.swing.JLabel();
        textDiretor = new javax.swing.JTextField();
        labelChefeTecnico = new javax.swing.JLabel();
        textChefeTecnico = new javax.swing.JTextField();
        labelSede = new javax.swing.JLabel();
        textSede = new javax.swing.JTextField();
        labelPneus = new javax.swing.JLabel();
        textPneus = new javax.swing.JTextField();
        labelChassi = new javax.swing.JLabel();
        textChassi = new javax.swing.JTextField();
        labelMotor = new javax.swing.JLabel();
        textMotor = new javax.swing.JTextField();
        labelPrimeiraTemporada = new javax.swing.JLabel();
        labelCampeaoMundialConstrutores = new javax.swing.JLabel();
        labelMelhorPosicaoCorrida = new javax.swing.JLabel();
        labelPolePosition = new javax.swing.JLabel();
        labelVoltasMaisRapidas = new javax.swing.JLabel();
        labelPontos = new javax.swing.JLabel();
        labelCampoCodigo = new javax.swing.JLabel();
        labelPrimeiraTemporada1 = new javax.swing.JLabel();
        labelCampeaoMundialConstrutores1 = new javax.swing.JLabel();
        labelMelhorPosicaoCorrida1 = new javax.swing.JLabel();
        labelPolePosition1 = new javax.swing.JLabel();
        labelVoltasMaisRapidas1 = new javax.swing.JLabel();
        labelPontos1 = new javax.swing.JLabel();
        panelBotoes = new javax.swing.JPanel();
        buttonSalvar = new javax.swing.JButton();
        buttonLimpar = new javax.swing.JButton();
        labelCamposObrigatorios = new javax.swing.JLabel();
        buttonNovo = new javax.swing.JButton();

        setBorder(null);
        setClosable(true);
        setForeground(java.awt.Color.white);
        setIconifiable(true);
        setTitle("Cadastro de Equipes");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });

        panelTitulo.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        labelTitulo.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        labelTitulo.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        labelTitulo.setText("Tela utilizada para cadastrar e/ou alterar dados da Equipe (Independente da Temporada)");

        javax.swing.GroupLayout panelTituloLayout = new javax.swing.GroupLayout(panelTitulo);
        panelTitulo.setLayout(panelTituloLayout);
        panelTituloLayout.setHorizontalGroup(
            panelTituloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelTituloLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelTitulo)
                .addContainerGap(114, Short.MAX_VALUE))
        );
        panelTituloLayout.setVerticalGroup(
            panelTituloLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelTituloLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelTitulo)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        panelDadosPrincipais.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "   Dados Principais   ", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 10), java.awt.Color.black)); // NOI18N

        panelEquipesCadastradas.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "   Equipes   ", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 10), java.awt.Color.black)); // NOI18N
        panelEquipesCadastradas.setPreferredSize(new java.awt.Dimension(232, 152));

        listEquipes.setToolTipText("Lista de equipes cadastradas");
        listEquipes.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                listEquipesValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(listEquipes);

        javax.swing.GroupLayout panelEquipesCadastradasLayout = new javax.swing.GroupLayout(panelEquipesCadastradas);
        panelEquipesCadastradas.setLayout(panelEquipesCadastradasLayout);
        panelEquipesCadastradasLayout.setHorizontalGroup(
            panelEquipesCadastradasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
        );
        panelEquipesCadastradasLayout.setVerticalGroup(
            panelEquipesCadastradasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1)
        );

        labelNomeCompleto.setText("Nome Completo: *");

        labelNome.setText("Nome: *");

        labelDiretor.setText("Diretor:");

        labelChefeTecnico.setText("Chefe Técnico:");

        labelSede.setText("Sede:");

        labelPneus.setText("Pneus:");

        labelChassi.setText("Chassi:");

        labelMotor.setText("Motor:");

        labelPrimeiraTemporada.setText("Primeira temporada:");

        labelCampeaoMundialConstrutores.setText("Campeonatos mundiais:");

        labelMelhorPosicaoCorrida.setText("Melhor posição em corridas:");

        labelPolePosition.setText("Pole Position:");

        labelVoltasMaisRapidas.setText("Voltas mais rápidas:");

        labelPontos.setText("Pontos:");

        labelCampoCodigo.setText("Campo código");
        labelCampoCodigo.setToolTipText("Não editar");

        labelPrimeiraTemporada1.setText("Valores");

        labelCampeaoMundialConstrutores1.setText("Valores");

        labelMelhorPosicaoCorrida1.setText("Valores");

        labelPolePosition1.setText("Valores");

        labelVoltasMaisRapidas1.setText("Valores");

        labelPontos1.setText("Valores");

        javax.swing.GroupLayout panelDadosPrincipaisLayout = new javax.swing.GroupLayout(panelDadosPrincipais);
        panelDadosPrincipais.setLayout(panelDadosPrincipaisLayout);
        panelDadosPrincipaisLayout.setHorizontalGroup(
            panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelDadosPrincipaisLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelCampeaoMundialConstrutores)
                    .addComponent(labelPrimeiraTemporada)
                    .addComponent(labelMelhorPosicaoCorrida)
                    .addComponent(labelPolePosition)
                    .addComponent(labelVoltasMaisRapidas)
                    .addComponent(labelPontos))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelPontos1)
                    .addComponent(labelVoltasMaisRapidas1)
                    .addComponent(labelPolePosition1)
                    .addComponent(labelMelhorPosicaoCorrida1)
                    .addComponent(labelCampeaoMundialConstrutores1)
                    .addComponent(labelPrimeiraTemporada1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(panelEquipesCadastradas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(panelDadosPrincipaisLayout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelNomeCompleto)
                    .addComponent(labelNome)
                    .addComponent(labelDiretor)
                    .addComponent(labelChefeTecnico)
                    .addComponent(labelSede)
                    .addComponent(labelPneus)
                    .addComponent(labelChassi)
                    .addComponent(labelMotor))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(textNomeCompleto, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(panelDadosPrincipaisLayout.createSequentialGroup()
                        .addComponent(textNome, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(labelCampoCodigo))
                    .addComponent(textDiretor, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textChefeTecnico, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textSede, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textPneus, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textChassi, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textMotor, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        panelDadosPrincipaisLayout.setVerticalGroup(
            panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelDadosPrincipaisLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelNomeCompleto)
                    .addComponent(textNomeCompleto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelNome)
                    .addComponent(textNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelCampoCodigo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelDiretor)
                    .addComponent(textDiretor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelChefeTecnico)
                    .addComponent(textChefeTecnico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelSede)
                    .addComponent(textSede, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelPneus)
                    .addComponent(textPneus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelChassi)
                    .addComponent(textChassi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelMotor)
                    .addComponent(textMotor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelDadosPrincipaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelDadosPrincipaisLayout.createSequentialGroup()
                        .addComponent(labelPrimeiraTemporada)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(labelCampeaoMundialConstrutores)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(labelMelhorPosicaoCorrida)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(labelPolePosition)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(labelVoltasMaisRapidas)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(labelPontos))
                    .addComponent(labelPrimeiraTemporada1)
                    .addGroup(panelDadosPrincipaisLayout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(labelCampeaoMundialConstrutores1))
                    .addGroup(panelDadosPrincipaisLayout.createSequentialGroup()
                        .addGap(40, 40, 40)
                        .addComponent(labelMelhorPosicaoCorrida1))
                    .addGroup(panelDadosPrincipaisLayout.createSequentialGroup()
                        .addGap(60, 60, 60)
                        .addComponent(labelPolePosition1))
                    .addGroup(panelDadosPrincipaisLayout.createSequentialGroup()
                        .addGap(80, 80, 80)
                        .addComponent(labelVoltasMaisRapidas1))
                    .addGroup(panelDadosPrincipaisLayout.createSequentialGroup()
                        .addGap(100, 100, 100)
                        .addComponent(labelPontos1))))
            .addComponent(panelEquipesCadastradas, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 333, Short.MAX_VALUE)
        );

        panelBotoes.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        buttonSalvar.setText("Salvar");
        buttonSalvar.setToolTipText("Clique para salvar os dados digitados");
        buttonSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonSalvarActionPerformed(evt);
            }
        });

        buttonLimpar.setText("Limpar");
        buttonLimpar.setToolTipText("Clique para limpar a tela e habilitar um novo registro");
        buttonLimpar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonLimparActionPerformed(evt);
            }
        });

        labelCamposObrigatorios.setText("Campos marcados com *, são obrigatórios");

        buttonNovo.setText("Novo");
        buttonNovo.setToolTipText("Clique para cadastrar um novo registro");
        buttonNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonNovoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelBotoesLayout = new javax.swing.GroupLayout(panelBotoes);
        panelBotoes.setLayout(panelBotoesLayout);
        panelBotoesLayout.setHorizontalGroup(
            panelBotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelBotoesLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelCamposObrigatorios)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(buttonNovo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buttonSalvar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buttonLimpar)
                .addContainerGap())
        );

        panelBotoesLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonLimpar, buttonNovo, buttonSalvar});

        panelBotoesLayout.setVerticalGroup(
            panelBotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelBotoesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelBotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(buttonLimpar)
                    .addComponent(buttonSalvar)
                    .addComponent(labelCamposObrigatorios)
                    .addComponent(buttonNovo))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(panelDadosPrincipais, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(panelTitulo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(panelBotoes, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panelTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelDadosPrincipais, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelBotoes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(21, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
        // TODO add your handling code here:
        clearFields();
    }//GEN-LAST:event_formComponentShown

    private void buttonSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSalvarActionPerformed
        // TODO add your handling code here:
        try{
            checkFields();

            createObject();

            clearFields();
        }catch(IllegalArgumentException e){
            JOptionPane.showMessageDialog(this, e.getMessage(), "Erro!", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_buttonSalvarActionPerformed

    private void listEquipesValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listEquipesValueChanged
        // TODO add your handling code here:
        if(this.listEquipes.getSelectedIndex() != -1){
            Team team1 = Library.returnTeam( (String)this.listEquipes.getSelectedValue());
            if(team1 != null){
                this.team = team1;
                this.emEdicao = true;
            }
        }
        dataShowObject();
    }//GEN-LAST:event_listEquipesValueChanged

    private void buttonLimparActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonLimparActionPerformed
        // TODO add your handling code here:
        clearFields();
    }//GEN-LAST:event_buttonLimparActionPerformed

    private void buttonNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonNovoActionPerformed
        // TODO add your handling code here:
        this.novo = true; //Diz para o clearFields() que sera um novo registro
        clearFields();
    }//GEN-LAST:event_buttonNovoActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonLimpar;
    private javax.swing.JButton buttonNovo;
    private javax.swing.JButton buttonSalvar;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel labelCampeaoMundialConstrutores;
    private javax.swing.JLabel labelCampeaoMundialConstrutores1;
    private javax.swing.JLabel labelCampoCodigo;
    private javax.swing.JLabel labelCamposObrigatorios;
    private javax.swing.JLabel labelChassi;
    private javax.swing.JLabel labelChefeTecnico;
    private javax.swing.JLabel labelDiretor;
    private javax.swing.JLabel labelMelhorPosicaoCorrida;
    private javax.swing.JLabel labelMelhorPosicaoCorrida1;
    private javax.swing.JLabel labelMotor;
    private javax.swing.JLabel labelNome;
    private javax.swing.JLabel labelNomeCompleto;
    private javax.swing.JLabel labelPneus;
    private javax.swing.JLabel labelPolePosition;
    private javax.swing.JLabel labelPolePosition1;
    private javax.swing.JLabel labelPontos;
    private javax.swing.JLabel labelPontos1;
    private javax.swing.JLabel labelPrimeiraTemporada;
    private javax.swing.JLabel labelPrimeiraTemporada1;
    private javax.swing.JLabel labelSede;
    private javax.swing.JLabel labelTitulo;
    private javax.swing.JLabel labelVoltasMaisRapidas;
    private javax.swing.JLabel labelVoltasMaisRapidas1;
    private javax.swing.JList listEquipes;
    private javax.swing.JPanel panelBotoes;
    private javax.swing.JPanel panelDadosPrincipais;
    private javax.swing.JPanel panelEquipesCadastradas;
    private javax.swing.JPanel panelTitulo;
    private javax.swing.JTextField textChassi;
    private javax.swing.JTextField textChefeTecnico;
    private javax.swing.JTextField textDiretor;
    private javax.swing.JTextField textMotor;
    private javax.swing.JTextField textNome;
    private javax.swing.JTextField textNomeCompleto;
    private javax.swing.JTextField textPneus;
    private javax.swing.JTextField textSede;
    // End of variables declaration//GEN-END:variables

    //Metodos reescritos da interface InterfaceRegister
    @Override
    public void dataShowObject() {
        this.textNomeCompleto.setText(this.team.getFullName());
        this.textNome.setText(this.team.getShortName());
        this.textDiretor.setText(this.team.getTeamPrincipal());
        this.textChefeTecnico.setText(this.team.getTechinicalChief());
        this.textSede.setText(this.team.getBase());
        this.textPneus.setText(this.team.getTyres());
        this.textChassi.setText(this.team.getChassis());
        this.textMotor.setText(this.team.getEngine());

        this.labelPrimeiraTemporada1.setText(""+this.team.getFirstSeason());
        this.labelCampeaoMundialConstrutores1.setText(""+this.team.getWorldChampionchips());
        this.labelMelhorPosicaoCorrida1.setText(""+this.team.getHighestRaceFinish()[0]+" (x"+this.team.getHighestRaceFinish()[1]+")");
        this.labelPolePosition1.setText(""+this.team.getPolePositions());
        this.labelVoltasMaisRapidas1.setText(""+this.team.getFastesLaps());
        this.labelPontos1.setText(""+this.team.getPoints());

        Library.indexedListTeams(this.listEquipes, FrameMain.getTeams(), null);
    }

    @Override
    public void checkFields() throws IllegalArgumentException {
        if(this.textNomeCompleto.getText().equals("")
        || this.textNome.getText().equals("")) {
            throw new IllegalArgumentException("Campos obrigatórios estão vazios.");
        }
    }

    @Override
    public void checkValueEntered() throws IllegalArgumentException, ParseException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void createObject() throws IllegalArgumentException {
        //Se nao estiver em modo de edicao entao adiciona, pois eh um novo Objeto, caso contrario apenas alterara
        if (!this.emEdicao) {
            if(Library.returnTeam(this.textNome.getText()) != null){
                throw new IllegalArgumentException("Equipe com Nome '"+this.textNome.getText()+"' já cadastrada.");
            }
            this.team.setShortName(this.textNome.getText());
            FrameMain.setTeams(this.team);
        }

        //Em todos os caso, ira alterar os dados do objeto
        this.team.setFullName(this.textNomeCompleto.getText());
        this.team.setTeamPrincipal(this.textDiretor.getText());
        this.team.setTechinicalChief(this.textChefeTecnico.getText());
        this.team.setBase(this.textSede.getText());
        this.team.setTyres(this.textPneus.getText());
        this.team.setChassis(this.textChassi.getText());
        this.team.setEngine(this.textMotor.getText());

        ManagementFiles.writeTeam(FrameMain.getTeams());
    }

    @Override
    public void clearFields(){
        this.team = new Team();
        this.emEdicao = false;

        if(!this.novo){
            this.listEquipes.setSelectedIndex(0);
        }
        this.novo = false;

        dataShowObject();
        Library.indexedListTeams(this.listEquipes, FrameMain.getTeams(), null);
    }
}
